package com.zepher.springboot.controller;

import com.zepher.springboot.common.Result;
import com.zepher.springboot.entity.Account;
import com.zepher.springboot.entity.Admin;
import com.zepher.springboot.entity.User;
import com.zepher.springboot.service.AdminService;
import com.zepher.springboot.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebController {

    @Resource
    private UserService userService;
    @Resource
    private AdminService adminService;

    // 登录
    @PostMapping("/login")
    public Result login(@RequestBody Account account){
        Account resutl = null;
        if ("user".equals(account.getRole())){
            resutl = userService.login(account);

        } else if ("admin".equals(account.getRole())){
            resutl = adminService.login(account);
        }
        return Result.success(resutl);
    }

    @PostMapping("/register")
    public Result register(@RequestBody User user){
        userService.register(user);
        return Result.success();
    }

}
